using System.Linq;
using DataAccess.Services.Interfaces;
using DataControl;
using DataControl.Entities;
using NHibernate;
using System.Collections.Generic;

namespace DataAccess.Services.Gateways
{
	class CurrencyGateway : GatewayBase<Currency>, ICurrencyGateway
	{
		public CurrencyGateway(ISession session) : base(session)
		{
		}

		public bool Exists(string currencyCode)
		{
			return DataControl.IsCurrencyExist(currencyCode);
		}

		public ICurrency Get(int currencyId)
		{
			return DataControl.GetCurrencyById(currencyId);
		}

		public IList<Currency> GetSupportedCurrencies()
		{
			return DataControl.GetAllItems<Currency>();
		}

		public Currency GetByCode(string code)
		{
			return DataControl.GetFiltredItems<Currency>("Code", new[] {code}).FirstOrDefault();
		}
	}
}